using System;
using System.Data;
using DayPilot.Web.Ui.Enums;


public partial class Scheduler_Day : System.Web.UI.Page
{
    private DataTable table;

    protected void Page_Load(object sender, EventArgs e)
    {
        #region Data loading initialization
        if (Session["Day"] == null)
        {
            Session["Day"] = DataGenerator.GetData();
        }
        table = (DataTable)Session["Day"];
        DayPilotNavigator1.DataSource = Session["Day"];
        DayPilotScheduler1.DataSource = Session["Day"];
        #endregion
        

        if (!IsPostBack)
        {
            DayPilotScheduler1.StartDate = DateTime.Today;
            DataBind();
        }
    }

    protected void DayPilotScheduler1_EventMove(object sender, DayPilot.Web.Ui.Events.EventMoveEventArgs e)
    {
        #region Simulation of database update

        DataRow dr = table.Rows.Find(e.Value);
        if (dr != null)
        {
            dr["start"] = e.NewStart;
            dr["end"] = e.NewEnd;
            dr["column"] = e.NewResource;
            table.AcceptChanges();
        }

        #endregion

        DayPilotScheduler1.DataBind();
        DayPilotScheduler1.Update();
    }

    protected void DayPilotScheduler1_EventResize(object sender, DayPilot.Web.Ui.Events.EventResizeEventArgs e)
    {
        #region Simulation of database update

        DataRow dr = table.Rows.Find(e.Value);
        if (dr != null)
        {
            dr["start"] = e.NewStart;
            dr["end"] = e.NewEnd;
            table.AcceptChanges();
        }

        #endregion

        DayPilotScheduler1.DataBind();
        DayPilotScheduler1.Update();
    }

    protected void DayPilotScheduler1_BeforeTimeHeaderRender(object sender, DayPilot.Web.Ui.Events.BeforeTimeHeaderRenderEventArgs e)
    {
        if (!e.IsColGroup)
        {
            e.InnerHTML = String.Format("<div style='color:gray; font-size:8pt; position:relative'><span style='position:relative; left: -10px;'>{0}</span></div>", e.InnerHTML);
        }
    }

    protected void DayPilotScheduler1_BeforeResHeaderRender(object sender, DayPilot.Web.Ui.Events.BeforeHeaderRenderEventArgs e)
    {
        if (!e.IsCorner)
        {
            e.InnerHTML = String.Format("<div style='line-height:1.2'>{0}<br /><span style='color:grey'>Second line</span></div>", e.InnerHTML);
        }
    }

    protected void DayPilotScheduler1_Command(object sender, DayPilot.Web.Ui.Events.CommandEventArgs e)
    {
        switch (e.Command)
        {
            case "navigate":
                DayPilotScheduler1.StartDate = (DateTime) e.Data["start"];
                DayPilotScheduler1.DataBind();
                DayPilotScheduler1.Update(CallBackUpdateType.Full);
                break;
        }
    }

    protected void DayPilotNavigator1_VisibleRangeChanged(object sender, DayPilot.Web.Ui.Events.Navigator.VisibleRangeChangedEventArgs e)
    {
        DayPilotNavigator1.DataBind();
    }

}
